package com.rss.provider.gmail.email.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;

import com.rss.provider.constant.NavigationConstant;
import com.rss.provider.spring.form.SubscriberForm;
import com.rss.provider.spring.form.UpdateForm;

@Service("GmailEmailSpringService")
public class GmailEmailSpringService {
	
	@Autowired
	@Qualifier("mailSender")
	private MailSender mailSender;

	public void sendMail(String from, String to, String subject, String body) {
		SimpleMailMessage message = new SimpleMailMessage();
		        message.setFrom(from);
		        message.setTo(to);
		        message.setSubject(subject);
		        message.setText(body);
		        mailSender.send(message);
		        
		     
	}

	public String sendMail(List<SubscriberForm> subscribers, UpdateForm updateForm) {
		SimpleMailMessage message = new SimpleMailMessage();
		message.setFrom(updateForm.getUpdateFrom());
		message.setSubject(updateForm.getUpdateSubject());
		message.setText(updateForm.getUpdateMessage());
		for (SubscriberForm subscriberForm : subscribers) {
			message.setTo(subscriberForm.getEmail());
			mailSender.send(message);
		}
		return NavigationConstant.SUCCESS;
	}

}
